package storage_define

type StorageCriteria interface {
	Field(field string) FormulaOp
}

type FormulaOp interface {
	Equal(val interface{}) JoinOp
}

type JoinOp interface {
	And() StorageCriteria
}

func NewCriteria() StorageCriteria {
	return &defaultStorageCriteria{
		list: make(map[string]FormulaOp),
	}
}

type defaultJoinOp struct {
	criteria StorageCriteria
}

func (d *defaultJoinOp) And() StorageCriteria {
	return d.criteria
}

type defaultStorageCriteria struct {
	list map[string]FormulaOp
}

func (c *defaultStorageCriteria) Field(field string) FormulaOp {

	criteria := &defaultFormulaOp{
		criteria: c,
	}
	c.list[field] = criteria

	return criteria
}

type defaultFormulaOp struct {
	op       string
	criteria StorageCriteria
	val      interface{}
}

func (o *defaultFormulaOp) Equal(val interface{}) JoinOp {
	o.op = "="
	o.val = val
	return &defaultJoinOp{
		criteria: o.criteria,
	}
}
